Repository navigation
Conversation
The single resident HTTP instance can now stay lightweight when idle. Gated by CODE_EXECUTOR_POOL_IDLE_MS (0 = disabled = eager, the default and the unchanged stdio behavior): - Lazy build: the downstream MCP pool is initialized on the FIRST tool call (SharedCore.ensurePoolReady, idempotent for concurrent callers) instead of eagerly at startup. - Idle teardown: when the last HTTP session closes, an idle timer tears the pool down (MCPClientPool.disconnect) after the configured window, reclaiming the ~15 downstream children; the next tool call rebuilds it. Teardown is deferred while an execution is in flight and cancelled on reconnect or full shutdown. - Session accounting is driven from the Streamable HTTP transport (onSessionOpen/onSessionClose), gated once per session on the sessions map. SharedCore gains optional constructor injection (pool + connection pool) for testability; production call sites are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the macOS launchd lifecycle for the single shared HTTP instance so it can run as an always-resident, managed service (a host cannot spawn an HTTP MCP server the way a stdio host does, so the server must already be running). - LaunchdService: renders a resident-daemon plist (RunAtLoad + KeepAlive, ProgramArguments=[binary], EnvironmentVariables carrying the http role, port, bearer token, MCP_CONFIG_PATH and CODE_EXECUTOR_ALLOW_NESTED) and manages it via modern launchctl verbs (bootstrap/bootout/kickstart/print). Distinct from the StartCalendarInterval sync scheduler. Plist written 0600 (it embeds the token); all interpolated values XML-escaped; label charset-validated so it cannot traverse out of ~/Library/LaunchAgents; launchctl runner + platform injectable for tests. - ensureHttpToken: read-or-generate a 256-bit bearer token persisted 0600 at ~/.code-executor/http-token (idempotent). - `code-executor-mcp service install|uninstall|status|restart` CLI (argv- dispatched like setup/sync-wrappers), with --port/--config/--binary/--no-auth and a connection hint for wiring a host. Verified live: install → launchd loads it → GET /health 200 → uninstall removes it cleanly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR2 — launchd lifecycle
Stacked on #13 (PR1 — HTTP core). Base is
feat/single-instance-http-server; GitHub will auto-retarget tomainwhen #13 merges. Reviewing after #13 shows only this PR's diff.Makes the single shared HTTP instance an always-resident, launchd-managed macOS service, and lets an idle resident stay lightweight.
1. Lazy/idle downstream pool (
✨ feat(core))Gated by
CODE_EXECUTOR_POOL_IDLE_MS(0 = disabled = eager, the default; stdio behavior byte-for-byte unchanged).SharedCore.ensurePoolReady, idempotent for concurrent callers), not eagerly at startup.onSessionOpen/Close), counted once per session.SharedCoregains optional constructor injection (pool + connection pool) for testability; production call sites unchanged.2. Resident launchd service +
serviceCLI (✨ feat(service))LaunchdService— renders a resident-daemon plist (RunAtLoad+KeepAlive,ProgramArguments=[binary],EnvironmentVariables= http role + port + bearer token +MCP_CONFIG_PATH+CODE_EXECUTOR_ALLOW_NESTED) and manages it via modernlaunchctlverbs (bootstrap/bootout/kickstart/print). Distinct from theStartCalendarIntervalsync scheduler. Plist written0600(embeds the token); all interpolated values XML-escaped; label charset-validated (no path traversal);launchctlrunner + platform injectable for tests.ensureHttpToken— read-or-generate a 256-bit bearer token persisted0600at~/.code-executor/http-token(idempotent).code-executor-mcp service install|uninstall|status|restart— argv-dispatched likesetup/sync-wrappers;--port/--config/--binary/--no-auth; prints a host connection hint.Verification
typecheckclean; 30 new unit tests green (launchd-service, http-token, idle-pool with fake timers).filesystem.test.tsenv-failure — no new regressions.--no-auth, self-cleaning):install→ launchd loads it →GET /health200 {"healthy":true,...}→uninstallremoves it cleanly.Deferred (not this PR)
Homebrew formula /
brew services,configure-hosts, token rotation, fullcectl(PR3/PR4). Per-session audit/rate-limit keys already landed in PR1 (#13).🤖 Generated with Claude Code